package com.kxq.zhuoyue.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.kxq.zhuoyue.po.Clients;
import com.kxq.zhuoyue.po.Result;
import com.kxq.zhuoyue.po.commodity;
import com.kxq.zhuoyue.service.ClientService;
import com.kxq.zhuoyue.service.commodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/commodity")
public class commodityController {
    @Autowired
    private commodityService commodityService;

    @GetMapping("/findAll")
    public Result findAll(){
        List<commodity> list = commodityService.list();
        return Result.success(list);
    }

    @PostMapping("/deletecom")
    public Result deletecom( int commodityId){
        boolean b = commodityService.removeById(commodityId);
        return Result.success(b);
    }
    @PostMapping("/insertcom")
    public Result insertcom(@RequestBody commodity commodity){
        boolean save = commodityService.save(commodity);
        return Result.success(save);
    }

    @PutMapping("/updatecom")
    public Result updatecom(@RequestBody commodity commodity){
        boolean b = commodityService.updateById(commodity);
        return Result.success(b);
    }
    @PostMapping("/findByNameLike")
    public Result findByNameLike(@RequestBody commodity commodity){
        QueryWrapper<commodity> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("userName",commodity.getUserName()); //查询条件 dname 等于 hello
        List<commodity> list = commodityService.list(queryWrapper);
        return Result.success(list);
    }



}
